
import 'package:basic_common/app_theme.dart';
import 'package:basic_common/common_exports.dart';
import 'package:basic_profile/model/phrases_data_list.dart';
import 'package:basic_widgets/app_bar_widget.dart';
import 'package:basic_widgets/button_widget.dart';
import 'package:basic_widgets/text_widget.dart';
import 'common_phrases_controller.dart';
class CommonPhrasesPage extends GetView<CommonPhrasesController> {
  const CommonPhrasesPage({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      appBar: backAppbar(title: "常用语句设置"),
      body: Container(
          height: ScreenHelper.screenHeight,
          width: ScreenHelper.screenWidth,
          padding: EdgeInsets.symmetric(horizontal: ScreenHelper.width(15)),
          child: Column(
            children: [
              Obx(
                () => controller.phrasesList.isEmpty
                    ? SizedBox.shrink()
                    : norTitle(title: "我的常用语句"),
              ),
              SizedBox(
                child: GetBuilder<CommonPhrasesController>(
                  id: 'phrasesList',
                  builder: (controller) => controller.phrasesList.length == 0
                      ? EmptyBox(title: "暂无数据")
                      : SizedBox(
                          child: ListView.separated(
                              shrinkWrap: true,
                              itemBuilder: (context, index) {
                                PhrasesData itemData =
                                    controller.phrasesList[index];
                                return buildItem(
                                    content: itemData.phrasesContent ?? '');
                              },
                              separatorBuilder: (context, index) => divider(),
                              itemCount: controller.phrasesList.length),
                        ),
                ),
              ),
              SizedBox(
                height: ScreenHelper.height(20),
              ),
              GestureDetector(
                onTap: () => showAddDialog(),
                child: Container(
                    width: ScreenHelper.screenWidth,
                    height: ScreenHelper.height(40),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        color: AppTheme.primyColor,
                        borderRadius: BorderRadius.circular(50)),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Icon(
                          Icons.add,
                          color: Colors.white,
                          size: ScreenHelper.width(16),
                        ),
                        Padding(
                          padding: EdgeInsets.all(4.0),
                          child: Text(
                            "添加",
                            textAlign: TextAlign.center,
                            style: TextStyle(
                                color: Colors.white,
                                fontSize: ScreenHelper.sp(16)),
                          ),
                        ),
                      ],
                    )),
              ),
              SizedBox(
                height: ScreenHelper.height(30),
              )
            ],
          )),
    );
  }

  Widget buildItem({required String content}) {
    return Container(
      color: Colors.white,
      height: 50,
      padding: EdgeInsets.symmetric(vertical: ScreenHelper.sp(10)),
      child: Text(
        "${content}",
        style: TextStyle(
            color: AppTheme.dartTextColor, fontSize: ScreenHelper.sp(16)),
      ),
    );
  }

  /// 添加dialog
  void showAddDialog() {
    showDialog(
        context: Get.context!,
        builder: (BuildContext context) {
          return Container(
            margin: const EdgeInsets.all(10.0),
            child: SimpleDialog(
              children: [
                //这边自己定义widget内容
                Center(
                  child: Container(
                    margin: EdgeInsets.symmetric(horizontal: 10),
                    child: TextField(
                      controller: controller.contentController,
                        style: const TextStyle(
                                    color: AppTheme.dartTextColor),
                      decoration:const InputDecoration(
                          hintText: "请输入常用语句",
                          border: OutlineInputBorder(
                              borderSide:
                                  BorderSide(color: AppTheme.primyColor)),
                          focusedBorder: OutlineInputBorder(
                              borderSide:
                                  BorderSide(color: AppTheme.primyColor)),
                          disabledBorder: OutlineInputBorder(
                              borderSide:
                                  BorderSide(color: AppTheme.primyColor)),
                          enabledBorder: OutlineInputBorder(
                              borderSide:
                                  BorderSide(color: AppTheme.primyColor))),
                    ),
                  ),
                ),
                SizedBox(
                  height: ScreenHelper.height(15),
                ),
                Container(
                  margin: EdgeInsets.symmetric(horizontal: 10),
                  child: Row(
                    children: [
                      Expanded(
                          child: roundBtn(
                              onTap: () {
                                Get.back();
                                controller.addPhrase();
                              },
                              text: "添加",
                              bgColor: AppTheme.primyColor,
                              textColor: Colors.white)),
                      SizedBox(
                        width: ScreenHelper.width(10),
                      ),
                      Expanded(
                          child: roundBtn(
                              onTap: () {
                                Get.back();
                              },
                              text: "取消",
                              bgColor: Colors.white,
                              textColor: AppTheme.primyColor,
                              borderColor: AppTheme.primyColor))
                    ],
                  ),
                )
              ],
            ),
          );
        });
  }
}
